package ru.amse.tsyganov.jumleditor.commands;

import ru.amse.tsyganov.jumleditor.properties.Property;


/*package*/ class ChangePropertyCommand extends Command {

	private final Property property;
	
	private final Object initialValue;
	
	private final Object newValue;
	
	public ChangePropertyCommand(Property property, Object newValue) {
		
		if (property == null || newValue == null || 
				newValue.equals(property.getPropertyValue())) {
			
			throw new IllegalArgumentException();
		}
		
		this.property = property;
		
		this.initialValue = property.getPropertyValue();
		
		this.newValue = newValue;
	}

	@Override
	public void execute() {
		property.setPropertyValueAndNotify(newValue);
	}

	@Override
	public void unexecute() {
		property.setPropertyValueAndNotify(initialValue);
	}

}
